<template>
    <div>
        <div v-if="re" style="background-color:#ecf8ff;border-left:5px solid #50bfff;border-radius:4px;font-size:16px;margin:15px 0;padding:8px 12px;width:100%;" class="title-style">{{kr_cp.title}}</div>
        <i-form :disabled="kr_cp.formDisabled" v-if="re" ref="form" :model="form" :label-position="kr_cp.form_lp" :label-width="kr_cp.form_lw === 'no'?null:kr_cp.form_lw" :label-colon="kr_cp.form_lc" scp-type="表单页面" style="padding:10px;" :rules="krRules" scp-layout="true">
            <Row :gutter="kr_cp.rowGutter" style="" type="flex" :justify="kr_cp.rowJustify" scp-layout="true">
                <i-col v-for="(item,index) in krForm" :key="index" :span="item.span?item.span:kr_cp.colSpan">
                    <div v-if="item.show === false?false:true">
                        <div v-if="item.modTitle" style="background-color:#ecf8ff;border-left:5px solid #50bfff;border-radius:4px;font-size:16px;margin:15px 0;padding:8px 12px;width:100%;" class="title-style">{{item.title}}</div>
                        <Form-item scp-allowparent="i-form" v-if="!item.modTitle" :label="item.label" :prop="item.rule?item.data:''" style="width:100%" :required="item.sRule?true:false">
                            <div style="padding-right:10px;min-height:10px;" scp-layout="true" class="form-element">
                                <i-input :disabled="item.disabled" v-if="item.type === 'i'" :maxlength="item.maxWord?item.maxWord:1000" :clearable="true" scp-type="输入框" style="" :size="kr_cp.componentSize" type="text" :placeholder="item.placeholder?item.placeholder:'请输入……'" v-model="form[item.data]"></i-input>
                                <i-input :disabled="item.disabled" v-if="item.type === 'in'" :maxlength="item.maxWord?item.maxWord:1000" :clearable="true" scp-type="输入框" style="" :size="kr_cp.componentSize" type="number" :placeholder="item.placeholder?item.placeholder:'请输入……'" v-model="form[item.data]"></i-input>
                                <i-input :disabled="item.disabled" v-if="item.type === 'ip'" :maxlength="item.maxWord?item.maxWord:18" :clearable="true" scp-type="输入框" style="" :size="kr_cp.componentSize" type="password" :placeholder="item.placeholder?item.placeholder:'请输入……'" v-model="form[item.data]"></i-input><Select :disabled="item.disabled" v-if="item.type === 's'" :clearable="true" v-on:on-change="krDFN(item.change,item.doC?true:false)" :filterable="true" scp-type="下拉框" style="width:100%;" :size="kr_cp.componentSize" :placeholder="item.placeholder?item.placeholder:'请选择……'" v-model="form[item.data]">
                                <Option :disabled="lItem.disabled" :value="lItem.value" v-for="(lItem,lIndex) in item.list" :key="lIndex">{{lItem.text?lItem.text:lItem.value}}</Option>
                            </Select>
                                <wl-tinymce
                                        :disabled="item.disabled"
                                        v-if="item.type === 'fwb'"
                                        :placeholder="item.placeholder?item.placeholder:'请输入……'"
                                        v-model="form[item.data]"
                                        :height="tinymceMod.height"
                                        :getSignUrl="tinymceMod.getSignUrl"
                                        :uploadUrl="tinymceMod.uploadUrl"
                                ></wl-tinymce>
                                <DatePicker :disabled="item.disabled" v-if="item.type === 'dp'" :clearable="true" v-on:on-change="krDFP($event,item.change)" style="width: 100%" placement="bottom" :size="kr_cp.componentSize" type="date" :placeholder="item.placeholder?item.placeholder:'请选择……'"></DatePicker>
                                <DatePicker :disabled="item.disabled" v-if="item.type === 'dpr'" :clearable="true" v-on:on-change="krDFPR($event,item.change)" style="width: 100%" placement="bottom" :size="kr_cp.componentSize" type="daterange" :placeholder="item.placeholder?item.placeholder:'请选择……'"></DatePicker>
                                <TimePicker :disabled="item.disabled" v-if="item.type === 'tp'" :clearable="true" v-on:on-change="krDFP($event,item.change)" style="width: 100%" placement="bottom" :size="kr_cp.componentSize" type="time" :placeholder="item.placeholder?item.placeholder:'请选择……'"></TimePicker>
                                <TimePicker :disabled="item.disabled" v-if="item.type === 'tpr'" :clearable="true" v-on:on-change="krDFPR($event,item.change)" style="width: 100%" placement="bottom" :size="kr_cp.componentSize" type="timerange" :placeholder="item.placeholder?item.placeholder:'请选择……'"></TimePicker>
                                <Radio-group :disabled="item.disabled" v-if="item.type === 'r'" v-on:on-change="krDFN(item.change,item.doC?true:false)" scp-type="单选框" style="" v-model="form[item.data]">
                                    <Radio :disabled="lItem.disabled" :label="lItem.value" :border="lItem.border?lItem.border:(item.border?item.border:kr_cp.radio_border)" v-for="(lItem,lIndex) in item.list" :size="kr_cp.componentSize" :key="lIndex">
                                        <Icon v-if="lItem.icon" :type="lItem.icon"></Icon><span v-if="lItem.text">{{lItem.text}}</span>
                                    </Radio>
                                </Radio-group><Input :disabled="item.disabled" v-if="item.type === 'ta'" :maxlength="item.maxWord?item.maxWord:1000" :rows="item.rows?item.rows:5" style="width: 100%" type="textarea" :show-word-limit="true" :placeholder="item.placeholder?item.placeholder:'请输入……'" v-model="form[item.data]"></Input>
                                <CheckboxGroup :disabled="item.disabled" v-if="item.type === 'c'" v-on:on-change="krDFN(item.change,item.doC?true:false)" v-model="form[item.data]">
                                    <Checkbox :disabled="lItem.disabled" :label="lItem.value" :border="lItem.border?lItem.border:(item.border?item.border:kr_cp.checkbox_border)" v-for="(lItem,lIndex) in item.list" :key="lIndex">
                                        <Icon v-if="lItem.icon" :type="lItem.icon"></Icon><span v-if="lItem.text">{{lItem.text}}</span>
                                    </Checkbox>
                                </CheckboxGroup>
                                <wl-select-city :disabled="item.disabled" v-if="item.type === 'sc'" style="width:100%;" :size="kr_cp.componentSize" :placeholder="item.placeholder?item.placeholder:'请选择……'" v-model="srMod[item.data]"></wl-select-city>
                                <wl-select-country :disabled="item.disabled" v-if="item.type === 'sct'" :clearable="true" :width="'100%'" :size="kr_cp.componentSize" :placeholder="item.placeholder?item.placeholder:'请选择……'" v-model="srMod[item.data]"></wl-select-country><span v-if="item.type === 'up'">
                                <Row>
                                    <wl-upload-oss-files :disabled="item.disabled?item.disabled:kr_cp.formDisabled" :max-num="item.upMaxNum?item.upMaxNum:uploadMod.maxNum" :upload-type="item.upType?item.upType:uploadMod.type" scp-type="上传文件" :format="item.upFormat?item.upFormat:uploadMod.format" :file-name="item.upFileName?item.upFileName:uploadMod.fileName" style="" :upload-url="item.uploadUrl?item.uploadUrl:uploadMod.uploadUrl" :get-sign-url="item.getSignUrl?item.getSignUrl:uploadMod.getSignUrl" v-model="form[item.data]"></wl-upload-oss-files>
                                </Row>
                                <Row><Button :disabled="item.disabled" v-if="form[item.data]?item.sf === false?false:item.sf === true?true:kr_cp.up_sf?true:false:false" size="small" v-on:click="krJumpPage(form[item.data],{},'new')" style="font-size:12px;width:61.5px" type="primary">查看文件</Button></Row>
                            </span><Button :disabled="item.disabled" v-if="item.type === 'sf'" v-on:click="krJumpPage(form[item.data],{},'new')" type="primary">查看文件</Button>
                                <div :ref="item.data" v-show="item.type === 'sfwb'"></div>
                            </div>
                        </Form-item>
                    </div>
                </i-col>
            </Row>
        </i-form>
        <Row v-if="re" justify="center" style="" type="flex" scp-layout="true">
            <Col v-if="pd == 0 || pd == 1" span="3"><Button v-on:click="krAction('insert')" :loading="kr_cp.btnLoading" type="success">
                新增
            </Button></Col>
            <Col v-if="pd == 2" span="3"><Button v-on:click="krAction('save')" :loading="kr_cp.btnLoading" type="primary">
                保存
            </Button></Col>
            <Col v-if="pd !== 0" span="3"><Button v-on:click="$router.go(-1)" type="default">
                返回
            </Button></Col>
        </Row>
    </div>
</template>

<script>
import { updateSstArticleNotice, insertSstArticleNotice, selectSstArticleNoticeById } from '@/api/dispatch'
export default {
  name: 'index',
  data () {
    return {
      're': true,
      'pd': 0,
      form: {
        content: ''
      },
      'krForm': [{
        'data': 'title',
        'rule': true,
        'label': '文章标题',
        'type': 'i',
        span: 8
      }, {
        data: 'author',
        'rule': true,
        'label': '作者',
        'type': 'i',
        span: 8
      }, {
        'data': 'upload_date',
        'sRule': true,
        'label': '发布日期',
        'type': 'dp',
        sDisplay: true,
        change: 'dateChange',
        span: 8
      }, {
        data: 'source',
        'rule': false,
        'label': '信息来源',
        'type': 'i',
        span: 12
      }, {
        data: 'type',
        'rule': true,
        'label': '文章类型',
        'type': 's',
        list: [
          { text: '通知公告', value: '1' },
          { text: '业务公告', value: '2' },
          { text: '政策法规', value: '3' },
          { text: '政策解读', value: '4' },
          { text: '放管服改革', value: '5' },
          { text: '服务事项高效办', value: '6' }
        ],
        span: 12
      }, {
        data: 'content',
        'sRule': true,
        'label': '文章内容',
        'type': 'fwb',
        span: 24
      }],
      'srMod': {},
      'uploadMod': {
        'fileName': 'origin',
        'uploadUrl': 'http://sstnewup.qstb.top/api/ac/file/fileCommonService/upLoadFiles',
        'format': ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx'],
        'getSignUrl': 'http://scptest.tripln.com/api/ac/form/projectService/getSign',
        'maxNum': 1,
        'type': 'hadoop'
      },
      'kr_cp': {
        'form_lp': 'top',
        'englishName': 'common parameters',
        'rowGutter': 16,
        'colSpan': '8',
        'formDisabled': false,
        'lv': '2.1',
        'btnLoading': false,
        'checkbox_border': false,
        'componentSize': 'default',
        'title': '新增文稿',
        'form_lc': true,
        'up_sf': true,
        'radio_border': false,
        'form_lw': 'no',
        'name': '公共参数',
        'rowAlign': 'middle',
        'rowJustify': 'start'
      },
      'krRules': {},
      'errorMsg': '',
      tinymceMod: {
        content: '',
        height: 400,
        getSignUrl: 'http://scptest.tripln.com/api/ac/form/projectService/getSign',
        uploadUrl: 'http://sstnewup.qstb.top/api/ac/file/fileCommonService/upLoadFiles'
      }
    }
  },
  mounted () {
    if (this.$route.query.pd) {
      this.pd = this.$route.query.pd
      if (this.pd >= 2) {
        // 单条接口
        selectSstArticleNoticeById({ id: this.$route.query.form.id }).then(res => {
          let data = res.data
          if (data.errcode === 0) {
            this.form = data.data
            if (this.form.id) {
              this.krForm.forEach(item => {
                if (item.sDisplay) {
                  item.show = true
                  item.placeholder = this.form[item.data]
                  if (item.type === 'sct') {
                    // 需要改成表单中的国家字段
                    this.srMod[item.data] = {
                      text: this.form.country
                    }
                  } else if (item.type === 'sc') {
                    // 需要改成表单中的省市区字段
                    this.srMod[item.data] = {
                      list: [{
                        label: this.form.sheng1
                      }, {
                        label: this.form.shi1
                      }, {
                        label: this.form.qu1
                      }]
                    }
                    item.placeholder = this.form.sheng1 + '/' + this.form.shi1 + '/' + this.form.qu1
                  } else {
                    this.srMod[item.change] = true
                  }
                }
              })
              this.goonpd()
            }
          } else {
            this.error(data.errmsg)
          }
        })
      }
    }
    this.getRules()
  },
  methods: {
    goonpd () {
      if (this.pd >= 3) {
        // this.kr_cp.formDisabled = true
        this.krForm.forEach(item => {
          item.disabled = true
          if (item.sfSign) {
            item.type = 'sf'
            item.disabled = false
          }
          if (item.type === 'fwb') {
            item.type = 'sfwb'
            this.$refs[item.data][0].innerHTML = this.form[item.data]
          }
        })
      }
    },
    dateChange (val) {
      this.form.upload_date = val
    },
    krCheckIDCard (num) { // 身份证校验
      num = num + ''
      num = num.toUpperCase()
      // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。
      if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
        this.errorMsg = '输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。'
        return false
      }
      // 校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
      // 下面分别分析出生日期和校验位
      let len, re
      len = num.length
      if (len === 15) {
        re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/)
        let arrSplit = num.match(re)
        // 检查生日日期是否正确
        let dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4])
        let bGoodDay
        bGoodDay = (dtmBirth.getYear() === Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) === Number(arrSplit[3])) && (dtmBirth.getDate() === Number(arrSplit[4]))
        if (!bGoodDay) {
          this.errorMsg = '输入的身份证号里出生日期不对！'
          return false
        } else {
          // 将15位身份证转成18位
          // 校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
          let arrInt = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
          let arrCh = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
          let nTemp = 0
          let i
          num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6)
          for (i = 0; i < 17; i++) {
            nTemp += num.substr(i, 1) * arrInt[i]
          }
          num += arrCh[nTemp % 11]
          return true
        }
      }
      if (len === 18) {
        re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/)
        let arrSplit = num.match(re)
        // 检查生日日期是否正确
        let dtmBirth = new Date(arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4])
        let bGoodDay
        bGoodDay = (dtmBirth.getFullYear() === Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) === Number(arrSplit[3])) && (dtmBirth.getDate() === Number(arrSplit[4]))
        if (!bGoodDay) {
          this.errorMsg = '输入的身份证号里出生日期不对！'
          return false
        } else {
          // 检验18位身份证的校验码是否正确。
          // 校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
          let valnum
          let arrInt = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
          let arrCh = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
          let nTemp = 0
          let i
          for (i = 0; i < 17; i++) {
            nTemp += num.substr(i, 1) * arrInt[i]
          }
          valnum = arrCh[nTemp % 11]
          if (valnum !== num.substr(17, 1)) {
            this.errorMsg = '18位身份证的校验码不正确！'
            return false
          }
          return true
        }
      }
      return false
    },
    krAction (ac_pd) {
      // console.log(this.scMod.name)
      let ruleNum = 0
      let validPass = true
      this.krForm.forEach((item, index) => {
        if (item.rule) {
          ruleNum++
        }
      })
      if (ruleNum > 0) { // 有基础校验
        this.$refs.form.validate((valid) => {
          if (valid) {} else {
            validPass = false
            this.error('必填项未填！')
          }
        })
      }
      if (validPass) {
        let isNull = 0
        let fErrMsg = true
        let cache_city_index = 0
        let cache_city = [ // 真实form的对应省市区字段名
          ['province', 'city', 'area'],
          ['sheng2', 'shi2', 'qu2']
        ]
        // let cache_country_index = 0
        // let cache_country = [ // 真实form的对应国家和编号字段名(单个字段不必填此表,默认传中文,若需要多个字段，需要填此表)
        //   ['cn_country1', 'code1'],
        //   ['cn_country2', 'code2']
        // ]
        this.krForm.forEach((item, index) => {
          if (item.data === 'card_no') {
            if (this.krCheckIDCard(this.form.card_no)) {} else {
              isNull++
              if (fErrMsg) {
                this.errorMsg = item.label + '格式不正确，请查验'
                fErrMsg = false
              }
            }
          }
          if (item.show !== false) {
            if (item.type === 'sc') {
              if (this.srMod[item.data] && this.srMod[item.data].list[0]) {
                this.form[cache_city[cache_city_index][0]] = this.srMod[item.data].list[0].label // 省
                this.form[cache_city[cache_city_index][1]] = this.srMod[item.data].list[1].label // 市
                this.form[cache_city[cache_city_index][2]] = this.srMod[item.data].list[2].label // 区
                cache_city_index++
              } else {
                if (item.sRule) {
                  isNull++
                  if (fErrMsg) {
                    this.errorMsg = item.label + '为必填项'
                    fErrMsg = false
                  }
                }
              }
            } else if (item.type === 'sct') {
              if (this.srMod[item.data]) {
                this.form[item.data] = this.srMod[item.data].text // text中文,en英文,tel编号
                // this.form[cache_country[cache_country_index[0]]] = this.srMod[item.data].text
                // this.form[cache_country[cache_country_index[1]]] = this.srMod[item.data].tel
                // cache_country_index++
              } else {
                if (item.sRule) {
                  isNull++
                  if (fErrMsg) {
                    this.errorMsg = item.label + '为必填项'
                    fErrMsg = false
                  }
                }
              }
            } else if (item.type === 'dp' || item.type === 'dpr' || item.type === 'tp' || item.type === 'tpr') {
              if (this.srMod[item.change]) {

              } else {
                if (item.sRule) {
                  isNull++
                  if (fErrMsg) {
                    this.errorMsg = item.label + '为必填项'
                    fErrMsg = false
                  }
                }
              }
            } else if (item.type === 'c') {
              if (this.form[item.data] && this.form[item.data].length > 0) {} else {
                if (item.sRule) {
                  isNull++
                  if (fErrMsg) {
                    this.errorMsg = item.label + '为必填项'
                    fErrMsg = false
                  }
                }
              }
            }
          }
        })
        if (isNull > 0) {
          this.error(this.errorMsg)
        } else {
          if (ac_pd === 'insert') {
            insertSstArticleNotice(this.form).then(res => {
              let data = res.data
              if (data.errcode === 0) {
                this.success('新增成功')
                this.$router.push('/gov/dispatch-manage-list')
              } else {
                this.error(data.errmsg)
              }
            })
          } else if (ac_pd === 'save') {
            updateSstArticleNotice(this.form).then(res => {
              let data = res.data
              if (data.errcode === 0) {
                this.success('保存成功')
                this.$router.push('/gov/dispatch-manage-list')
              } else {
                this.error(data.errmsg)
              }
            })
          }
        }
      }
    },
    krJumpPage (path, param, type) {
      if (type === 'router') {
        this.$router.push({
          path: path,
          query: {
            param
          }
        })
      } else if (type === 'new') {
        window.location.href = path
      } else {
        this.error('页面跳转类型错误')
      }
    },
    inspected_dateChange (val) {
      this.form.inspected_date = val
    },
    error (msg, time, close) {
      let krTime = 3
      if (time) {
        krTime = time
      }
      let krClose = false
      if (close === true || close === 'true' || close === '1') {
        krClose = true
      }
      this.$Message.error({
        content: msg,
        duration: krTime,
        closable: krClose
      })
    },
    kr_warehouse () { // 仓库
      // krForm参数说明
      // form为真实数据源,krForm为页面渲染配置
      // krForm中的每一项都为一个表单项，内部详细属性说明如下:
      // "span": 8 // 行宽占比(单独配置),24为一整行,可无,默认为kr_cp.colSpan(统一配置)
      // "show":false // 是否显示,可无,默认为true
      // "modTitle": false, // 是否是模块标题,如果是,span需设置为24,可无
      // "title": "模块标题", // modTitle指定为true时的模块标题,可无
      // "label": "姓名", // 表单项名
      // "data": "name", // 数据源字段名
      // "type": "i", // 填报模块类型:i输入框,in数字框,ip密码框,s下拉框,r单选框,c复选框,dp日期选择,dpr日期段选择,tp时间选择,tpr时间段选择,ta文本域,up文件上传,sc省市区列表(需要在submitAction()方法中写真实字段),sct国家列表
      // "rule": 1, // 基础校验,满足真则有校验,默认为非空校验,校验规则可在getRules()方法中自定义(某些不支持校验的模块不推荐使用),可无
      // "sRule":1, // 特殊校验,校验基础校验无法匹配的模块,适用于type为c,dp,dpr,tp,tpr,sc,sct,可无,注意不能与rule共同为真
      // "placeholder": "请输入……", // 占位文本,有默认值,可无
      // "border": false, // type为r或c时,群组设置是否带边框,可无,type为r时默认为kr_cp.radio_border,type为c时默认为,kr_cp.checkbox_border
      // "list": [{ // 当type为s或者r或者c时的选项列表,可无
      //     "text": "Karenloar", // 显示文本
      //     "value": "KR", // 真实值,若无text,显示文本也为此值
      //     "disabled": false, // 是否可选,可无,默认可选
      //     "border": false, // type为r或c时,单项设置是否带边框,可无,type为r时默认为kr_cp.radio_border,type为c时默认为,kr_cp.checkbox_border
      //     "icon": "logo-twitter" // type为r或c时,icon图标
      // }, {
      //     "text": "renpeng",
      //     "value": "renpeng"
      // }],
      // "change": "functionName", // change事件名,需定义对应事件,支持默认传参(只有一位),可无
      // "doC": 1, // 适用type为s、r、c的情况,是否执行change事件,可无,默认不执行
      // "rows": 7,  // 当type为ta时,默认高度(行高),可无,默认5
      // "maxWord": 1000, // 当type为i,in,ip,ta时的输入上限,可无,i,ta默认1000,in默认14,ip默认18
      // "sf":true, // 当type为up时，是否显示查看文件按钮(单独配置),可无,默认为kr_cp的up_sf(统一配置)
      // "sfSign":true, // 当type为up时,pd为查看详情功能时,关闭上传入口，只留查看文件按钮
      // "upMaxNum":1, // 当type为up时的最大上传数(单独配置),可无,默认为文件上传模块uploadMod的maxNum(统一配置)
      // "upType": "hadoop", // 当type为up时的上传类型(单独配置),可无,默认为文件上传模块uploadMod的type(统一配置)
      // "upFormat": ["jpg", "jpeg", "png", "pdf"], // 当type为up时的上传格式(单独配置),可无,默认为文件上传模块uploadMod的format(统一配置)
      // "upFileName": "origin", // 当type为up时的上传文件名(单独配置),可无,默认为文件上传模块uploadMod的fileName(统一配置)
      // "getSignUrl": "", // 当type为up时的获取签名接口(单独配置),可无,默认为文件上传模块uploadMod的getSignUrl(统一配置)
      // "uploadUrl": "", // 当type为up时的上传接口(单独配置),可无,默认为文件上传模块uploadMod的uploadUrl(统一配置)

      // kr_cp参数说明
      // "lv": "2.1", // 版本号
      // "up_sf": true, // 文件上传是否显示查看文件按钮
      // "form_lp": "top", // form表单label样式,可选left,right,top
      // form_lw: 'no', // form表单label宽度,form_lp不为top时需要,不需要则填'no'
      // form_lc: true, // form表单label结尾是否显示冒号
      // "englishName": "common parameters", // 对象英文名
      // "rowGutter": 16, // row中每个col的间距,推荐(16+8n)px
      // "colSpan": "8", // row中每个col的占比
      // "name": "公共参数", // 对象名
      // "rowAlign": "middle", // row的align属性,可选top,bottom,middle
      // "componentSize": "default", // 全局组件的size,可选small,default,large
      // "rowJustify": "start", // row的justify属性,可选start,end,center,space-between,space-around
      // "radio_border": false, // 单选框是否带边框
      // "checkbox_border": false, // 复选框是否带边框
      // "formDisabled": false // 表单整体禁用

      // 自定义校验样例
      // this.krRules[item.data].push({
      //     message: '输入必须为数字,格式:整数2至3位,小数(可无)1至2位',
      //     trigger: 'change',
      //     pattern: /^(\d{2,3})(\.\d{1,2})?$/
      // })
    },
    krTrim (type, val) { // 去空格函数
      val = val + ''
      if (type === 'left' || type === 'trim' || type === 'all') {
        while ((val.indexOf(' ') === 0) && (val.length > 1)) {
          val = val.substring(1, val.length)
        }
      }
      if (type === 'right' || type === 'trim' || type === 'all') {
        while ((val.lastIndexOf(' ') === val.length - 1) && (val.length > 1)) {
          val = val.substring(0, val.length - 1)
        }
      }
      if (val === ' ') {
        val = ''
      } else if (type === 'all') {
        while (val.indexOf(' ') !== -1) {
          val = val.substring(0, val.indexOf(' ')) + val.substring(val.indexOf(' ') + 1, val.length)
        }
      }
      return val
    },
    success (msg, time, close) {
      let krTime = 3
      if (time) {
        krTime = time
      }
      let krClose = false
      if (close === true || close === 'true' || close === '1') {
        krClose = true
      }
      this.$Message.success({
        content: msg,
        duration: krTime,
        closable: krClose
      })
    },
    krDFPR (e, f) {
      if (e[0]) {
        this.srMod[f] = true
      } else {
        this.srMod[f] = false
      }
      this[f](e[0], e[1])
    },
    getRules () {
      this.krForm.forEach((item, index) => {
        if (item.rule) {
          this.krRules[item.data] = [{
            'trigger': 'blur',
            'message': '该字段为必填字段',
            'required': true
          }]
        }
      })
      // 以上只加上了非空校验，如有其它需求自行添加
      this.re = false
      let num = 0
      setTimeout(() => {
        this.re = true
      }, num)
    },
    krCheckTel (num) { // 手机号规则校验
      num = num + ''
      if (!(/^[1][3,4,5,7,8][0-9]{9}$/.test(num))) {
        this.errorMsg = '输入的手机号格式不正确'
        return false
      } else {
        return true
      }
    },
    krDFN (f, doit) {
      if (doit) this[f]()
    },
    krDFP (e, f) {
      if (e) {
        this.srMod[f] = true
      } else {
        this.srMod[f] = false
      }
      this[f](e)
    }
  }
}
</script>

<style scoped>

</style>
